import request from '@/config/axios'

// 报价单 VO
export interface QuotationVO {
  id: number // 编号
  projectName: string // 项目名称
  quoteNumber: string // 报价单编号
  customerId: number // 客户编号
  ownerUserId: number // 负责人的用户编号
  status: number // 审批状态
  orderDate: Date // 下单日期
  startTime: Date // 开始时间
  endTime: Date // 结束时间
  totalProductPrice: number // 产品总金额（未税）
  discountPercent: number // 整单折扣
  totalPrice: number // 合同总金额（含税）
  finalPrice: number // 合同总金额(优惠后)
  totalProductPricePrefix: string // 产品总金额（未税）大写金额
  totalPricePrefix: string // 合同总金额（含税）大写金额
  finalPricePrefix: string // 合同总金额(优惠后)大写金额
  selfName: string // 我方企业名称
  selfAddress: string // 我方企业地址
  selfContactPerson: string // 联系人
  selfTel: string // 联系电话
  selfEmail: string // 联系邮箱
  remark: string // 备注
}

// 报价单 API
export const QuotationApi = {
  //获得当前用户信息
  getCurrentUserInfo: async () => {
    return await request.get({ url: `/system/user/profile/get` })
  },

  //申请退回报价单
  applyQuotation: async (data: any) => {
    return await request.put({ url: `/quote/quotation/return`, data })
  },

  //报价单pdf导出
  exportQuotationPdf: async (params: any) => {
    return await request.download({ url: `/quote/export/pdf?quoteNumber=${params.quoteNumber}` })
  },
  // 提交报价单
  submitQuotation: async (data: any) => {
    return await request.post({ url: `/quote/quotation/submit`, data })
  },

  // 审核报价单
  auditQuotation: async (data: any) => {
    return await request.put({ url: `/quote/quotation/audit`, data })
  },

  // 获得所有状态数据
  getAllStatus: async () => {
    return await request.get({ url: `/quote/quotation/count` })
  },
  // 查询报价单分页
  getQuotationPage: async (params: any) => {
    if (JSON.stringify(params.status).indexOf('审批中') != -1) {
      params.status = [10, 40]
    }
    return await request.get({ url: `/quote/quotation/page`, params })
  },

  // 查询报价单详情
  getQuotation: async (no: number, id: number) => {
    return await request.get({ url: `/quote/quotation/get?quoteNumber=${no}&id=` + id })
  },

  // 新增报价单
  createQuotation: async (data: QuotationVO) => {
    return await request.post({ url: `/quote/quotation/create`, data })
  },

  // 修改报价单
  updateQuotation: async (data: QuotationVO) => {
    return await request.put({ url: `/quote/quotation/update`, data })
  },

  // 删除报价单
  deleteQuotation: async (id: number, quoteNumber: string) => {
    return await request.delete({
      url: `/quote/quotation/delete?id=${id}&quoteNumber=${quoteNumber}`
    })
  },

  // 导出报价单 Excel
  exportQuotationExcel: async (params) => {
    if (JSON.stringify(params.status).indexOf('审批中') != -1) {
      params.status = [10, 40]
    }
    return await request.download({ url: `/quote/quotation/export-excel`, params })
  },

  //根据报价单编号获取附件列表
  getAttachmentListByQuotationNo: async (params: any) => {
    return await request.get({ url: `/quote/quotation-file/list/${params}` })
  },
  deleteAttachment: async (params) => {
    return await request.delete({ url: `/quote/quotation-file/delete`, params })
  },
  downloadAttachment: async (id) => {
    return await request.download({ url: `/quote/quotation-file/download/${id}` })
  }
}
